<?php
include '/var/www/raybt/data/www/raybt.ru/admin/DBConnector/idiorm/config2.php';
if (isset($_POST['proxy'])) {

    $proxy_server_arr = explode("\n", $_POST['proxy']['proxy_server']);
    $proxy_arr = explode("\n", $_POST['proxy']['proxy']);

    $model = ORM::for_table('parser_proxies');


    if (!empty($_POST['proxy']['proxyuser'])) {

        $model->where('proxyuser', $_POST['proxy']['proxyuser'])->delete();

        $arr = array(
            'proxy' => $proxy_arr,
            'proxy_server' => $proxy_server_arr,
            'proxyuser' => $_POST['proxy']['proxyuser'],
            'proxypass' => $_POST['proxy']['proxypass'],
            'proxyport' => $_POST['proxy']['proxyport'],
        );

      

        for ($i = 0; $i < count($arr['proxy']); $i++) {
            
            

            $proxy = ORM::for_table('parser_proxies')->create();

            $proxy->proxy = $arr['proxy'][$i];
            $proxy->proxy_server = $arr['proxy_server'][$i];
            $proxy->proxyuser = $arr['proxyuser'];
            $proxy->proxypass = $arr['proxypass'];
            $proxy->proxyport = $arr['proxyport'];
            
            $proxy->save();
            
        }
        
        
        $msg = "Удалены все проси адресса с логином: " . $arr['proxyuser'];
        $msg .= '<br>' . 'Добавлненно адрессов: ' . $i;
        $msg = "<a href=''>Назад</a>";
        echo $msg;
        

    } else {
        
        echo "Укажите все поля";    
    }

//    print_r($listArr);
    die();
}
?>

<html>              
    <head>
        <title>Управление прокси</title>
    </head>

    <body>
    <center>
        <form method="post" action="" style="">


            <table>

                <thead>
                    <tr>
                        <td>Прокси-адресса</td>
                        <td>Имя прокси</td>

                        <td>Порт</td>

                        <td>Пользователь</td>
                        <td>Пароль<td>

                    </tr>
                </thead>

                <tbody>
                    <tr>
                        <td>
                            <textarea row="10" cols="5" name="proxy[proxy]" style="width: 200px; height: 500px"></textarea>
                        </td>
                        <td>
                            <textarea row="10" cols="5" name="proxy[proxy_server]" style="width: 200px; height: 500px"></textarea>
                        </td>
                        <td>
                            <input type="text" name="proxy[proxyport]">
                        </td>
                        <td>
                            <input type="text" name="proxy[proxyuser]">
                        </td>
                        <td>
                            <input type="text" name="proxy[proxypass]">
                        </td>
                    </tr>
                </tbody>

            </table>

            <input type="submit" name="proxy[submit]" value="Загрузить">
        </form>
    </center>
</body>
</html>


<?php die(); ?>